package copyengine.ui.component.button
{
    import copyengine.ui.component.button.animation.ICESelectableButtonAnimation;

    import starling.display.DisplayObject;

    public class CESelectableButton extends CEButton
    {
        private var mIsSelected:Boolean;
        private var mIsClickToSelected:Boolean;

        public function CESelectableButton(_targetMc:DisplayObject)
        {
            super(_targetMc);
        }

        /**
         * 取得当前按钮选择状态
         */
        public function get isSelected():Boolean
        { return mIsSelected; }

        /**
         * 设置当前按钮选择状态
         */
        public function set isSelected(_val:Boolean):void
        {
            if (mIsSelected != _val) {
                mIsSelected = _val;
                selectableAnimation.onSelectedChange(mIsSelected);
            }
        }

        /**
         * 如果改值为True则表示每次点击会自动更改按钮的选择状态
         */
        public function get isClickToSelect():Boolean
        { return mIsClickToSelected; }

        /**
         * 如果改值为True则表示每次点击会自动更改按钮的选择状态
         */
        public function set isClickToSelect(_val:Boolean):void
        { mIsClickToSelected = _val; }

        override protected function doOnClickButton():void
        {
            if (mIsClickToSelected) {isSelected = !isSelected;}
        }

        //========================//
        //==Private  Function
        //=========================//

        private function get selectableAnimation():ICESelectableButtonAnimation
        {
            return mAnimation as ICESelectableButtonAnimation;
        }

    }
}
